home *** CD-ROM | disk | FTP | other *** search
- integer PCon1, PCon2, PCon3, PCon4;
- real planet1[], planet2[], planet3[], planet4[];
- integer half[4], hidden[4];
-
- constant fieldSize is 200;
-
- constant xLowBound is 0;
- constant xHiBound is 200;
- constant yLowBound is 0;
- constant yHiBound is 200;
-
- constant earth is "Earth";
- constant mars is "Mars";
- constant venus is "Venus";
- constant moon is "Moon";
- constant sun is "Sun";
-
- ** Planet Plotter block
- ** Copyright © 1993 by Imagine That, Inc.
- ** All rights reserved.
- ** J. Steven Lamperti 3/10/93
- ** modified
- **
-
- // Planetary array elements
- //
- // planet[0] = mass;
- // planet[1] = x;
- // planet[2] = y;
- // planet[3] = planetID;
- // planet[4] = density;
-
-
- procedure makePicture(integer obj, integer ID)
- {
- if (ID == 1)
- AnimationPicture(obj, earth, TRUE);
- else if (ID == 2)
- AnimationPicture(obj, mars, TRUE);
- else if (ID == 3)
- AnimationPicture(obj, venus, TRUE);
- else if (ID == 4)
- AnimationPicture(obj, moon, TRUE);
- else if (ID == 5)
- AnimationPicture(obj, sun, TRUE);
- else
- AnimationPicture(obj, moon, TRUE);
- }
-
-
- procedure stretchPicture(integer obj, real mass, real density)
- {
- integer size;
- real ratio;
-
- ratio = mass/density;
- size = (fieldSize * ratio) / (maxX - minX);
- size = size + size * 0.20; // 20% bigger for visual collisions
-
- if (size > 60)
- size = 60;
-
- if (size < 2)
- size = 2;
-
- AnimationStretchTo(obj, 0, 0, size, size, FALSE);
- half[obj-1] = size/2;
- }
-
-
- procedure draw(integer useLast)
- {
- real x1, y1, x2, y2, x3, y3, x4, y4;
-
- if (pCon1)
- {
- if (!useLast)
- {
- GetPassedArray(planet1In, planet1);
- if (currentStep == 0)
- {
- stretchPicture(1, planet1[0], planet1[4]);
- makePicture(1, planet1[3]);
- }
- }
-
- x1 = (planet1[1] - minX) / (maxX - minX) * fieldSize;
- y1 = fieldSize + (minY - planet1[2]) / (maxY - minY) * fieldSize;
- if (x1 < xLowBound)
- {
- AnimationHide(1, FALSE);
- Hidden[0] = 1;
- }
- else
- {
- AnimationMoveTo(1, x1 - half[0], y1 - half[0], FALSE);
- if (Hidden[0] || useLast)
- AnimationShow(1);
- Hidden[0] = 0;
- }
- }
-
- if (pCon2)
- {
- if (!useLast)
- {
- GetPassedArray(planet2In, planet2);
- if (currentStep == 0)
- {
- stretchPicture(2, planet2[0], planet2[4]);
- makePicture(2, planet2[3]);
- }
- }
-
- x2 = (planet2[1] - minX) / (maxX - minX) * fieldSize;
- y2 = fieldSize + (minY - planet2[2]) / (maxY - minY) * fieldSize;
- if (x2 < xLowBound)
- {
- AnimationHide(2, FALSE);
- Hidden[1] = 1;
- }
- else
- {
- AnimationMoveTo(2, x2 - half[1], y2 - half[1], FALSE);
- if (Hidden[1] || useLast)
- AnimationShow(2);
- Hidden[1] = 0;
- }
- }
-
- if (pCon3)
- {
- if (!useLast)
- {
- GetPassedArray(planet3In, planet3);
- if (currentStep == 0)
- {
- stretchPicture(3, planet3[0], planet3[4]);
- makePicture(3, planet3[3]);
- }
- }
-
- x3 = (planet3[1] - minX) / (maxX - minX) * fieldSize;
- y3 = fieldSize + (minY - planet3[2]) / (maxY - minY) * fieldSize;
- if (x3 < xLowBound)
- {
- AnimationHide(3, FALSE);
- Hidden[2] = 1;
- }
- else
- {
- AnimationMoveTo(3, x3 - half[2], y3 - half[2], FALSE);
- if (Hidden[2] || useLast)
- AnimationShow(3);
- Hidden[2] = 0;
- }
- }
-
- if (pCon4)
- {
- if (!useLast)
- {
- GetPassedArray(planet4In, planet4);
- if (currentStep == 0)
- {
- stretchPicture(4, planet4[0], planet4[4]);
- makePicture(4, planet4[3]);
- }
- }
-
- x4 = (planet4[1] - minX) / (maxX - minX) * fieldSize;
- y4 = fieldSize + (minY - planet4[2]) / (maxY - minY) * fieldSize;
- if (x4 < xLowBound)
- {
- AnimationHide(4, FALSE);
- Hidden[3] = 1;
- }
- else
- {
- AnimationMoveTo(4, x4 - half[3], y4 - half[3], FALSE);
- if (Hidden[3] || useLast)
- AnimationShow(4);
- Hidden[3] = 0;
- }
- }
- }
-
-
-
- // This message occurs for each step in the simulation.
- on simulate
- {
- if (animationOn)
- draw(FALSE);
- }
-
-
- on EndSim
- {
- if (animationOn)
- draw(TRUE);
- }
-
-
- // If the dialog data is inconsistent for simulation, abort.
- on checkdata
- {
- integer i;
-
- PCon1 = planet1In;
- PCon2 = planet2In;
- PCon3 = planet3In;
- PCon4 = planet4In;
-
- AnimationHide(1, TRUE);
- AnimationHide(2, TRUE);
- AnimationHide(3, TRUE);
- AnimationHide(4, TRUE);
-
- for(i = 0; i < 4; i++)
- hidden[i] = 1;
-
- if (maxX - minX != maxY - minY)
- Usererror("It is reccommended that you keep the plotters X dimension area equal to the plotters Y dimension area.");
- }
-
-
-
- on createBlock
- {
- minX = -50.0;
- minY = -50.0;
- maxX = 50.0;
- maxY = 50.0;
- }
-